package com.huawei.updatesdk.a.a.c;

import com.huawei.updatesdk.a.a.b.a.a.a;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public abstract class c {
    public static String a(String str, String str2) {
        FileInputStream fileInputStream;
        Throwable e;
        Throwable th;
        String str3 = null;
        if (str != null) {
            try {
                MessageDigest instance = MessageDigest.getInstance(str2);
                fileInputStream = new FileInputStream(str);
                try {
                    byte[] bArr = new byte[WXMediaMessage.DESCRIPTION_LENGTH_LIMIT];
                    long j = 0;
                    while (true) {
                        int read = fileInputStream.read(bArr);
                        if (read == -1) {
                            break;
                        }
                        instance.update(bArr, 0, read);
                        j += (long) read;
                    }
                    if (j > 0) {
                        str3 = b.a(instance.digest());
                    }
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException e2) {
                            a.d("FileUtil", "Close FileInputStream failed!");
                        }
                    }
                } catch (NoSuchAlgorithmException e3) {
                    e = e3;
                    try {
                        a.a("FileUtil", "getFileHashData NoSuchAlgorithmException", e);
                        if (fileInputStream != null) {
                            try {
                                fileInputStream.close();
                            } catch (IOException e4) {
                                a.d("FileUtil", "Close FileInputStream failed!");
                            }
                        }
                        return str3;
                    } catch (Throwable th2) {
                        th = th2;
                        if (fileInputStream != null) {
                            try {
                                fileInputStream.close();
                            } catch (IOException e5) {
                                a.d("FileUtil", "Close FileInputStream failed!");
                            }
                        }
                        throw th;
                    }
                } catch (FileNotFoundException e6) {
                    e = e6;
                    a.a("FileUtil", "getFileHashData FileNotFoundException", e);
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException e7) {
                            a.d("FileUtil", "Close FileInputStream failed!");
                        }
                    }
                    return str3;
                } catch (IOException e8) {
                    e = e8;
                    a.a("FileUtil", "getFileHashData IOException", e);
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException e9) {
                            a.d("FileUtil", "Close FileInputStream failed!");
                        }
                    }
                    return str3;
                } catch (IllegalArgumentException e10) {
                    e = e10;
                    a.a("FileUtil", "getFileHashData IllegalArgumentException", e);
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException e11) {
                            a.d("FileUtil", "Close FileInputStream failed!");
                        }
                    }
                    return str3;
                } catch (IndexOutOfBoundsException e12) {
                    e = e12;
                    a.a("FileUtil", "getFileHashData IndexOutOfBoundsException", e);
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException e13) {
                            a.d("FileUtil", "Close FileInputStream failed!");
                        }
                    }
                    return str3;
                }
            } catch (NoSuchAlgorithmException e14) {
                e = e14;
                fileInputStream = null;
                a.a("FileUtil", "getFileHashData NoSuchAlgorithmException", e);
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
                return str3;
            } catch (FileNotFoundException e15) {
                e = e15;
                fileInputStream = null;
                a.a("FileUtil", "getFileHashData FileNotFoundException", e);
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
                return str3;
            } catch (IOException e16) {
                e = e16;
                fileInputStream = null;
                a.a("FileUtil", "getFileHashData IOException", e);
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
                return str3;
            } catch (IllegalArgumentException e17) {
                e = e17;
                fileInputStream = null;
                a.a("FileUtil", "getFileHashData IllegalArgumentException", e);
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
                return str3;
            } catch (IndexOutOfBoundsException e18) {
                e = e18;
                fileInputStream = null;
                a.a("FileUtil", "getFileHashData IndexOutOfBoundsException", e);
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
                return str3;
            } catch (Throwable e19) {
                fileInputStream = null;
                th = e19;
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
                throw th;
            }
        }
        return str3;
    }

    public static void a(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (Throwable e) {
                a.a("FileUtil", "Closeable exception", e);
            }
        }
    }

    public static boolean a(File file) {
        if (file == null || !file.exists()) {
            return true;
        }
        if (file.isFile()) {
            return file.delete();
        }
        File[] listFiles = file.listFiles();
        if (listFiles != null && listFiles.length > 0) {
            for (File a : listFiles) {
                a(a);
            }
        }
        return file.delete();
    }
}
